﻿function showForm(_idDiv,_idDescription, _idRule, _timeStart, _timeStop,_inPutStart,_inPutStop,_inPutHour,_idInPutMulti) {
    var _idRuleTmp = _idRule.split('#');
    if(_inPutStart==undefined){_inPutStart="inPutStart";}
    if(_inPutStop==undefined){_inPutStop="inPutStop";}
    if(_inPutHour==undefined){_inPutHour="inPutHour";}
    if(_idInPutMulti==undefined){_idInPutMulti="inPutMulti";}
    //showDescription(_idDescription, _idRuleTmp[1]); Version 2013, Do not show rule description, Edit by: Niyom R., Date 13/02/2013 11:25
    showMultiTitle(_idRuleTmp[1],"show");

    var _url="../rule/Rule.ashx";
    var _data = {
        action: "ShowFrom"
        , id: _idRuleTmp[1]
        , start: _timeStart
        , stop: _timeStop
        , ipstart: _inPutStart
        , ipstop: _inPutStop
        , iphour: _inPutHour
        , ipmulti: _idInPutMulti
    };
    var _function = function (data) {
        if (data != "") {
            var _json = JSON.parse(data);

            $("#" + _idDiv).html(_json["html"]);
            if (_idRule != "-") {
                showTimePickerRun(_inPutStart);
                showSelectStop(_inPutStop, _inPutStart, _inPutHour);
            }
            var _checkDay = _json["checkDay"];
            getDateInput(parseInt(_checkDay[0]), "insert", _checkDay[1], _checkDay[2]);
            showFormDay(_checkDay, "insert");
            inputValid();
        }
    };
    webAjax(_url, _data, _function);
}
function editForm(_idDiv,_idDescription, _idRule, _timeStart, _timeStop, _inPutMulti, _inPutStart,_inPutStop, _inPutHour,_idInPutMulti) {
    var _idRuleTmp = _idRule.split('#');
    var _arrTimeStart,_arrTimeStop;
    if(_timeStart==undefined){_timeStart="08:00";}else{
        _arrTimeStart=_timeStart.split(':');
        _timeStart=_arrTimeStart[0]+":"+_arrTimeStart[1];
    }
    if(_timeStop==undefined){_timeStop="08:00";}else{
        _arrTimeStop=_timeStop.split(':');
        _timeStop=_arrTimeStop[0]+":"+_arrTimeStop[1];
    }
    if(_inPutStart==undefined){_inPutStart="inPutStart";}
    if(_inPutStop==undefined){_inPutStop="inPutStop";}
    if(_inPutHour==undefined){_inPutHour="inPutHour";}
    if(_idInPutMulti==undefined){_idInPutMulti="inPutMulti";}
    //showDescription(_idDescription, _idRuleTmp[1]); Version 2013, Do not show rule description, Edit by: Niyom R., Date 13/02/2013 11:25
    showMultiTitle(_idRuleTmp[1], "edit");

    var _url = "../rule/Rule.ashx";
    var _data = {
        action: "ShowFrom"
        , id: _idRuleTmp[1]
        , start: _timeStart
        , stop: _timeStop
        , inPutMulti: _inPutMulti
        , ipstart: _inPutStart
        , ipstop: _inPutStop
        , iphour: _inPutHour
        , ipmulti: _idInPutMulti
    }
    var _function = function (data) {
        if (data !== "") {
            var _json = JSON.parse(data);
            $("#" + _idDiv).html(_json["html"]);
            if (_idRule != "-") {
                showTimePickerRun(_inPutStart);
                //showSelectStop(_inPutStop,_inPutStart,_inPutHour);
                processTime(_inPutStart, _inPutStop, _inPutHour);
                showTimePickerRun(_inPutStop);
            }
            var _checkDay = _json["checkDay"];
            getDateInput(parseInt(_checkDay[0]), "edit", _checkDay[1], _checkDay[2]);
            showFormDay(_checkDay, "edit");
            inputValid();
        }
    };
    webAjax(_url, _data, _function);
}
function showFormTeach(_idDiv,_idDescription, _idRule, _timeStart, _timeStop,_inPutStart,_inPutStop,_inPutHour,_idInPutMulti,_PId,_TSId,_Querter,_Faculty,_Section) {
    var _idRuleTmp = _idRule.split('#');
    if(_inPutStart==undefined){_inPutStart="inPutStart";}
    if(_inPutStop==undefined){_inPutStop="inPutStop";}
    if(_inPutHour==undefined){_inPutHour="inPutHour";}
    if(_idInPutMulti==undefined){_idInPutMulti="inPutMulti";}
    showDescription(_idDescription, _idRuleTmp[1]);
    showMultiTitle(_idRuleTmp[1],"show");
    var _post = "action=ShowFromTeach&id=" + _idRuleTmp[1] + "&start=" + _timeStart + "&stop=" + _timeStop+"&ipstart="+_inPutStart+"&ipstop="+_inPutStop+"&iphour="+_inPutHour+"&ipmulti="+_idInPutMulti+"&pid="+_PId+"&tsid="+_TSId+"&quarter="+_Querter+"&faculty="+_Faculty+"&section="+_Section;
    $.ajax({
        url: "../rule/Rule.ashx",
        context: document.body,
        type: "POST",
        data: _post,
        charset: "tis-620",
        async: false,
        success: function (data) {
            var _json = JSON.parse(data);
            $("#" + _idDiv).html(_json["html"]);
            if (_idRule != "-") {
                showTimePickerRun(_inPutStart);
                showSelectStop(_inPutStop,_inPutStart,_inPutHour);
            }
            var _checkDay = _json["checkDay"];
            getDateInput(parseInt(_checkDay[0]), "edit", _checkDay[1], _checkDay[2]);
            showFormDay(_checkDay);
         
        }
    });
}
function editFormTeach(_idDiv,_idDescription, _idRule, _timeStart, _timeStop, _inPutMulti, _inPutStart,_inPutStop, _inPutHour,_idInPutMulti,_PId,_TSId,_Querter,_Faculty,_Section) {
    var _idRuleTmp = _idRule.split('#');
    var _arrTimeStart,_arrTimeStop;
    if(_timeStart==undefined){_timeStart="08:00";}else{
        _arrTimeStart=_timeStart.split(':');
        _timeStart=_arrTimeStart[0]+":"+_arrTimeStart[1];
    }
    if(_timeStop==undefined){_timeStop="08:00";}else{
        _arrTimeStop=_timeStop.split(':');
        _timeStop=_arrTimeStop[0]+":"+_arrTimeStop[1];
    }
    if(_inPutStart==undefined){_inPutStart="inPutStart";}
    if(_inPutStop==undefined){_inPutStop="inPutStop";}
    if(_inPutHour==undefined){_inPutHour="inPutHour";}
    if(_idInPutMulti==undefined){_idInPutMulti="inPutMulti";}
    showDescription(_idDescription, _idRuleTmp[1]);
    showMultiTitle(_idRuleTmp[1], "edit");
    var _post = "action=ShowFromTeach&id=" + _idRuleTmp[1] + "&start=" + _timeStart + "&stop=" + _timeStop+"&inPutMulti="+_inPutMulti+"&ipstart="+_inPutStart+"&ipstop="+_inPutStop+"&iphour="+_inPutHour+"&ipmulti="+_idInPutMulti+"&pid="+_PId+"&tsid="+_TSId+"&quarter="+_Querter+"&faculty="+_Faculty+"&section="+_Section;
    $.ajax({
        url: "../rule/Rule.ashx",
        context: document.body,
        type: "POST",
        data: _post,
        charset: "tis-620",
        async: false,
        success: function (data) {
            var _json = JSON.parse(data);
            $("#" + _idDiv).html(_json["html"]);
            if (_idRule != "-") {
                showTimePickerRun(_inPutStart);
                //showSelectStop(_inPutStop,_inPutStart,_inPutHour);
                processTime(_inPutStart,_inPutStop,_inPutHour);
                showTimePickerRun(_inPutStop);
            }
            var _checkDay = _json["checkDay"];
            getDateInput(parseInt(_checkDay[0]), "edit", _checkDay[1], _checkDay[2]);
            showFormDay(_checkDay);
        }
    });
}
function processTime(_inPutStart,_inPutStop,_inPutHour){
    var _start = $("#"+_inPutStart).val();
    var _stop = $("#"+_inPutStop).val();
    var _mode = "time";
    var _post = "action=ShowTime&start=" + _start + "&stop=" + _stop + "&mode=" + _mode;
    $.ajax({
        url: "../rule/Rule.ashx",
        context: document.body,
        type: "POST",
        data: _post,
        charset: "tis-620",
        success: function (data) {
            $("#"+_inPutHour+"SS").val(data);
            $("#"+_inPutHour).val(data);
            showTimeER(_inPutHour, data);
            //$.unblockUI(); // For end blockUI from load edit page
        }
    });
}
function showSelectStop(_inPutStop,_inPutStart,_inPutHour){
    var _start = $("#"+_inPutStart).val();
    var _stop = $("#"+_inPutStop).val();
    var _post = "action=showSelectStop&start=" + _start+"&stop="+_stop;
    $.ajax({
        url: "../rule/Rule.ashx",
        context: document.body,
        type: "POST",
        data: _post,
        charset: "tis-620",
        success: function (data) {
            $("#"+_inPutStop).val(data);
            showTimePickerRun(_inPutStop);
            processTime(_inPutStart,_inPutStop,_inPutHour);
        }
    });
    if(_inPutStart!="inPutStart"){
        //showSelectTime("stop","inPutStop","inPutStart","inPutHour",_start);
    }
}
function showSelectStart(_inPutStart,_inPutStop,_inPutHour) {
    var _start  = $("#"+_inPutStart).val();
    var _stop = $("#"+_inPutStop).val();
    var _post = "action=showSelectStart&start=" + _start+"&stop="+_stop;
    $.ajax({
        url: "../rule/Rule.ashx",
        context: document.body,
        type: "POST",
        data: _post,
        charset: "tis-620",
        success: function (data) {
            //$("#"+_inPutStart).val(data);
            showTimePickerRun(_inPutStart);
            processTime(_inPutStart,_inPutStop,_inPutHour);
        }
    });
    if(_inPutStop=="inPutStop"){
        //showSelectTime("start",_inPutStop+"2",_inPutStart+"2",_inPutHour+"2",_stop);
    }
}
function showSelectTime(_mode,_inPutStop,_inPutStart,_inPutHour,_value){
    var _status,_check;
    switch(_mode){
        case"start":
            _status=$("#"+_inPutHour+"Status").val();
            if(_status=="Default"){
                $("#"+_inPutStart).val(_value);
                showSelectStop(_inPutStop,_inPutStart,_inPutHour);
            }
            break;
        case"stop":
            _status=$("#"+_inPutHour+"Status").val();
            if(_status=="Default"){
                $("#"+_inPutStop).val(_value);
                processTime(_inPutStart,_inPutStop,_inPutHour);
            }
            break;
    }
}
function showDescription(description,id) {
    var _post = "action=showDescription&id=" + id;
    $.ajax({
        url: "../rule/Rule.ashx",
        context: document.body,
        type: "POST",
        data: _post,
        charset: "tis-620",
        success: function (data) {
            $("#" + description).html(data); 
        }
    });
}
function showMultiTitle(_id, _mode){
    var _multiTitle = $('#eHiddenTitle').val();
    var _originalRuleId = $("#eRid").val();
    //alert("Rule ID:"+_id + "-" + "Original ID:" + _originalRuleId); 
    var _arrTitle = new Array();
        if(_multiTitle!=undefined){
          _arrTitle = _multiTitle.split(',');
        }
    var _post = "action=showMultiTitle&id=" + _id;
    var _arrStatus;
    $.ajax({
        url: "../rule/Rule.ashx",
        context: document.body,
        type: "POST",
        data: _post,
        charset: "tis-620",
        async: false,
        success: function (data) {
            //alert(data);
            _arrStatus=data.split('#');
            if(_arrStatus[0]=="True"){ // Mutiple Titile
                if(_mode=="show"){
                    constructMultiTitle(_arrStatus[1]);
                }else if(_mode=="edit"){
                     if(_id == _originalRuleId){
                       constructEditMultiTitle(_arrStatus[1], _multiTitle);
                     }else{
                       constructEditMultiTitle(_arrStatus[1], '');
                     }   
                }
            }else{ //Signle Title
                 if(_id == _originalRuleId){
                     constructEditSigleTitle(_arrStatus[1], _multiTitle);
                 }else{
                     constructEditSigleTitle(_arrStatus[1], '');
                 }
            }
        }
    });
}
function showTimePickerRun(_id) {
    $("#"+_id).timepicker({
        hourGrid: 5,
        minuteGrid: 10,
        stepMinute: 10
    });
}
function showTimeER(_inPutHour,_data,_mode){
    var _txt;
    if(_data=="00:00"){
        _txt="<font color='red'>กรุณาเลือกเวลาให้ถูกต้อง</font>";
        $("#"+_inPutHour+"ER").html(_txt);
    }else{
        _txt="";
        $("#"+_inPutHour+"ER").html(_txt);
    }
    if(_mode=="return"){return _txt;}
}
function checkRuleError(_idHour, _idMulti){
    if(_idHour==undefined){_idHour="inPutHour";}
    if(_idMulti==undefined){_idMulti="inPutMulti";}
    var _timeStatus=$("#"+_idHour+"Status").val();
    var _titleMulti=$("#"+_idHour+"TitleMulti").val();
    var _txtTime="";//true false
    var _txtTmp="";//noteError
    var _status="";//true false
    if(_timeStatus=="Default"){
        _txtTime=showTimeER(_idHour,$("#"+_idHour).val(),"return");
        if(_txtTime==""){
            _txtTime=true;
        }else{
            _txtTime=false;
            _txtTmp=_txtTmp+"#กรุณาเลือกเวลาให้ถูกต้อง";
        }
    }else if(_timeStatus=="undefined"){
        _txtTime=true;
    }
    var _arrMulti=$("."+_idMulti);
    var _arrMultiNo=_arrMulti.length;
    var _txtMulti=true;
    if(_arrMultiNo>0){
        var _arrTitleMulti=_titleMulti.split('#');
        for(var i=0;i<_arrMulti.length;i++){
            var j=i+1;
            if(_arrMulti[i].value<=0){
                _txtMulti=false;
                _txtTmp=_txtTmp+"#กรุณากรอก"+_arrTitleMulti[j];
            }
        }
    }
    if(_txtTime&_txtMulti){_status=true;}else{_status=false;}
    return _status+","+_txtTmp;
}
function checkRuleErrorTeach(_idHour, _idMulti){
    if(_idHour==undefined){_idHour="inPutHour";}
    if(_idMulti==undefined){_idMulti="inPutMulti";}
    var _timeStatus=$("#"+_idHour+"Status").val();
    var _titleMulti=$("#"+_idHour+"TitleMulti").val();
    var _txtTime="";//true false
    var _txtTmp="";//noteError
    var _status="";//true false
    if(_timeStatus=="Default"){
        _txtTime=showTimeER(_idHour,$("#"+_idHour).val(),"return");
        if(_txtTime==""){
            _txtTime=true;
        }else{
            _txtTime=false;
            _txtTmp=_txtTmp+"#กรุณาเลือกเวลาให้ถูกต้อง";
        }
    }else if(_timeStatus=="undefined"){
        _txtTime=true;
    }
    var _arrMulti=$("."+_idMulti);
    var _arrMultiNo=_arrMulti.length;
    var _txtMulti=true;
    if(_arrMultiNo>0){
        var _arrTitleMulti=_titleMulti.split('#');
        for(var i=0;i<_arrMulti.length;i++){
            var j=i+1;
            if(_arrMulti[i].value<=0){
                _txtMulti=false;
                _txtTmp=_txtTmp+"#กรุณากรอก"+_arrTitleMulti[j];
            }
        }
    }
    if(_txtTime&_txtMulti){_status=true;}else{_status=false;}
    return _status+","+_txtTmp;
}
function checkRuleErrorTeachDuplicateTime(_statusLec, _statusLab, _pathHandler) {
    if (_pathHandler == undefined) {
        _pathHandler = "";
    }
    var _mode,_status=true,_txt="";
    if(_statusLec==true){_statusLec="1";}else{_statusLec="0";}
    if(_statusLab==true){_statusLab="1";}else{_statusLab="0";}
    _mode=_statusLec+_statusLab;
    if(_mode=="11"){
        var _hourStatusA=$("#inPutHourStatus").val();
        var _hourStatusB=$("#inPutHour2Status").val();
        if(_hourStatusA=="Default"&&_hourStatusB=="Default"){
            var _hourAStart=$("#inPutStart").val();
            var _hourAStop=$("#inPutStop").val();
            var _hourBStart=$("#inPutStart2").val();
            var _hourBStop=$("#inPutStop2").val();
            var _data = $.ajax({
                      url: _pathHandler + "TeachingScoreHandler.ashx",
                      global: false,
                      type: "POST",
                      data: "action=CheckRuleErrorTeachDuplicateTime&data="+_hourAStart+","+_hourAStop+","+_hourBStart+","+_hourBStop,
                      dataType: "html",
                      async:false/*,
                      success: function(data){
                         alert(data);
                      }*/
                   }
                ).responseText;
            if(_data=="False"){
            _txt="#เวลาสอนไม่สามารถซ้อนกันได้กรุณาเลือกเวลาให้ถูกต้อง";
            _status=false;
            }
        }
    }
    return _status+","+_txt;
}
function ShowTimeSession(_txt,_mode,_name){
    if(_txt==undefined){_txt="null";}
    if(_name==undefined){_name="sts";}
    if(_mode==undefined){_mode="write";}
    var _post = "action=ShowTimeSession&txt="+_txt+"&name=" + _name+"&mode="+_mode;
    $.ajax({
        url: "../rule/Rule.ashx",
        context: document.body,
        type: "POST",
        data: _post,
        charset: "tis-620",
        success: function (data) {
            if(_mode=="write"){
                }else if(_mode=="read"){
                alert(data);
            }
        }
    });
}
function inputValid() {
    inputValidGetValue();
    inputValidSet();
}
function inputValidSet() {
    //_mode     insert      edit

    //ModeFloat-------------------------------------------------------
    $("input[id~=ModeFloat]").keyup(function (even) {
        var _pattern = new RegExp('^([0-9]{1,3})?(\.[0-9]{0,2})$');
        var _madId = $(this).attr("madId");
        var _value = $(this).val();

        var _reg = _pattern.test(_value);
        var _status = "";
        if ((_reg) && ((parseFloat(_value) > 0) && (parseFloat(_value) < 1000))) {
            _status = "<img src='../images/png/16x16/accept(3).png' style='height:15px;'>";
            $("#" + _madId).val(parseFloat(_value));
        } else {
            _status = "<img src='../images/png/16x16/warning(3).png' style='height:15px;'> <font color='red'>กรุณากรอกตัวเลข <b><u>จำนวนเต็ม</u></b>(ทศนิยม 2 ตำแหน่ง) มากกว่า 0</font>";
            $("#" + _madId).val(0);
        }
        $("span[madId='" + _madId + "']").html(_status);
    });
    $("input[id~=ModeFloat]").focus(function () {
        var $this = $(this);
        $this.select();

        // Work around Chrome's little problem
        $this.mouseup(function () {
            // Prevent further mouseup intervention
            $this.unbind("mouseup");
            return false;
        });
    });

    //ModeInt-------------------------------------------------------
    $("input[id~=ModeInt]").keyup(function (even) {
        var _pattern = new RegExp("^([1-9]|[1-9][0-9]|[1-9][0-9][0-9]){1,3}$");
        var _madId = $(this).attr("madId");
        var _value = $(this).val();
        var _reg = _pattern.test(_value);
        var _status = "";
        if (_reg) {
            _status = "<img src='../images/png/16x16/accept(3).png' style='height:15px;'>";
            $("#" + _madId).val(parseInt(_value));
        } else {
            _status = "<img src='../images/png/16x16/warning(3).png' style='height:15px;'> <font color='red'>กรุณากรอกตัวเลข <b><u>จำนวนเต็ม</u></b> มากกว่า 0</font>";
            $("#" + _madId).val(0);
        }
        $("span[madId='" + _madId + "']").html(_status);
    });
    $("input[id~=ModeInt]").focus(function () {
        var $this = $(this);
        $this.select();

        // Work around Chrome's little problem
        $this.mouseup(function () {
            // Prevent further mouseup intervention
            $this.unbind("mouseup");
            return false;
        });
    });

    //ModeTime-------------------------------------------------------
    /*$("input[id~=ModeTime]").keyup(function (even) {
        var _pattern = new RegExp("^(?!00:00)(([0-9]|[0-9][0-9])\:([0-5]|[0-5][0-9]))$");
        var _madId = $(this).attr("madId");
        var _value = $(this).val();
        //_value = _value.replace(".", ":");
        //$(this).val(_value)
        var _reg = _pattern.test(_value);
        var _status = "";
        if (_reg) {
            _status = "<img src='../images/png/16x16/accept(3).png' style='height:15px;'>";
            var _url = "../rule/Rule.ashx";
            var _data = {
                action: "ProcessTime2Number"
                , timeStr: _value
            };
            $("input[madId=" + _madId + "]").attr("maxlength", "5");
            var _timeFloat = webAjax(_url, _data, undefined, "return");
            $("#" + _madId).val(_timeFloat);
        } else {
            _status = "<img src='../images/png/16x16/warning(3).png' style='height:15px;'> <font color='red'>กรุณากรอกเวลา <b><u>ชั่วโมง:นาที</u></b> มากกว่า 1 นาที</font>";
            $("#" + _madId).val(0);
        }
        $("span[madId='" + _madId + "']").html(_status);
    });
    $("input[id~=ModeTime]").focus(function () {
        var $this = $(this);
        $this.select();

        // Work around Chrome's little problem
        $this.mouseup(function () {
            // Prevent further mouseup intervention
            $this.unbind("mouseup");
            return false;
        });
    });*/
    $("input[id~=ModeTime]").timepicker({
        hourGrid: 5,
        minuteGrid: 10,
        stepMinute: 10,
        showButtonPanel: false
    });
    $("input[id~=ModeTime]").change(function () {
        var _madId = $(this).attr("madId");
        var _value = $(this).val();
       
        $("#" + _madId).val(_timeFloat);

        var _url = "../rule/Rule.ashx";
        var _data = {
            action: "ProcessTime2Number"
            , timeStr: _value
        };
        var _timeFloat = webAjax(_url, _data, undefined, "return");

        var _status = "";
        if (_timeFloat>0) {
            _status = "<img src='../images/png/16x16/accept(3).png' style='height:15px;'>";
            $("#" + _madId).val(_timeFloat);
        } else {
            _status = "<img src='../images/png/16x16/warning(3).png' style='height:15px;'> <font color='red'>กรุณากรอกเวลา <b><u>ชั่วโมง:นาที</u></b> มากกว่า 1 นาที</font>";
            $("#" + _madId).val(0);
        }
        $("span[madId='" + _madId + "']").html(_status);
    });

}
function inputValidGetValue() {
    var _objFloat = $("input[id~=ModeFloat]");
    for (var i = 0; i < _objFloat.length; i++) {
        var _madId = $(_objFloat[i]).attr("madId");
        var _float = parseFloat($("#" + _madId).val()).toFixed(2);
        $("input[madId=" + _madId + "]").attr("maxlength", "6");
        $("input[madId=" + _madId + "]").val(_float);
    }
    var _objInt = $("input[id~=ModeInt]");
    for (var i = 0; i < _objInt.length; i++) {
        var _madId = $(_objInt[i]).attr("madId");
        $("input[madId=" + _madId + "]").attr("maxlength", "3");
        $("input[madId=" + _madId + "]").val($("#" + _madId).val());
    }
    var _objTime = $("input[id~=ModeTime]");
    for (var i = 0; i < _objTime.length; i++) {
        var _madId = $(_objTime[i]).attr("madId");
        var _url = "../rule/Rule.ashx";
        var _data = {
            action: "ProcessTime2Time"
            ,timeFloat: $("#" + _madId).val()
        };
        $("input[madId=" + _madId + "]").attr("maxlength", "5");
        var _time = webAjax(_url, _data, undefined, "return");
        $("input[madId=" + _madId + "]").val(_time);
    }

    var _dayNo = $("#inputDayTxtTmp").val();
    var _dayHTML = '<input style="width: 50px; text-align: right;" disabled="disabled" maxLength="3" value="' + _dayNo + '" type="text">';
    $("#inputDaySpan").html(_dayHTML);
}


var showFormDayDataTmp;
function showFormDay(_data, _mode) {
    /*
        idMode
        labelStart
        labelStop
        RLInput
        RLUTitle
        RLUType
        inputDayMode
    */
    //inputDaySpan      inputDayTxtTmp
    //startDate         endDate
    var _idSTart = "", _idStop = "";
    showFormDayDataTmp = _data;
    switch (_mode) {
        case "insert":
            _idSTart = "startDate";
            _idStop = "endDate";
            break;
        case "edit":
            _idSTart = "startEDate";
            _idStop = "endEDate";
            $("#" + _idStop).datepicker("option", "minDate", $("#" + _idSTart).val());
            $("#" + _idSTart).datepicker("option", "maxDate", $("#" + _idStop).val());
            break;
    }
    if (_data[6] == "True") {//input
        $("#" + _idSTart).datepicker("option", "onClose", function (_selectedDate) {
            showFormDayDiff(_idSTart, _idStop);
            $("#" + _idStop).datepicker("option", "minDate", _selectedDate);
        });
        $("#" + _idStop).datepicker("option", "onClose", function (_selectedDate) {
            showFormDayDiff(_idSTart, _idStop);
            $("#" + _idSTart).datepicker("option", "maxDate", _selectedDate);
        });
    } else {//show
        $("#" + _idSTart).datepicker("option", "onClose", function (_selectedDate) {
            $("#" + _idStop).datepicker("option", "minDate", _selectedDate);
        });
        $("#" + _idStop).datepicker("option", "onClose", function (_selectedDate) {
            $("#" + _idSTart).datepicker("option", "maxDate", _selectedDate);
        });
    }
}
function showFormDayDiff(_idSTart, _idStop) {
    var _start, _end, _total;
    if (($("#" + _idSTart).val()) != "" && ($("#" + _idStop).val() != "")) {
        _start = $("#" + _idSTart).datepicker("getDate");
        _end = $("#" + _idStop).datepicker("getDate");
        _total = (_end - _start) / 1000 / 60 / 60 / 24;
        //  ms / sec / min / hour
        _total = _total + 1;
        if (_total < 0) { _total = 0; }
    }
    else {
        _total = 0;
    }
    var _day = showFormDayDiffConvert(_total);
    var _htm = '<input style="width: 50px; text-align: right;" disabled="disabled" maxLength="3" value="' + _day + '" type="text">';
    $("#inputDaySpan").html(_htm);
    $("#inputDayTxtTmp").val(_day);
}
function showFormDayDiffConvert(_day) {
    var _data;
    switch (showFormDayDataTmp[4]) {
        case "วัน":
            _data = _day;
            break;
        case "สัปดาห์":
            _data = (_day / 7).toFixed(0);
            break;
        case "เดือน":
            _data = (_day / 30).toFixed(0);
            break;
    }
    return _data;
}

//check regexe
//http://www.regular-expressions.info/javascriptexample.html
//http://www.regular-expressions.info/javascriptexample.html